<template>
	<view class="uniPopup" v-show="show">

		<!-- 弹窗 -->
		<view class="popup" v-show="show">
			<view type="center">
				<view class="imgs">
					<image class="imgss" :src="sku.img" mode=""></image>
				</view>

				<view class="background">
					<view class="name">
						<view class="cname">
							单人沙发
						</view>
						<view class="repertory">
							库存: {{sku.count}}
						</view>
					</view>
					<view class="icon" ref="close" :before-close="true" @close="close">
						<image @click="goDel" class="icons" src="../../../static/icons/x.png" mode=""></image>
					</view>



					<!-- 颜色分类 -->
					<view class="classify">
						<view class="text">
							颜色分类
						</view>
						<radio-group class="colors" @change="colorSel">
							<template v-if="skuList.length>0">
								<label class="color-item" :class="{active:sku.id==item.id}" v-for="item in skuList" :key="item.id">
									<view>
										<radio :style="{color:item.color}" :value="item.id" />
										<text>{{ item.color_text }}</text>
									</view>
									<view>{{item.name}}</view>
								</label>
							</template>
						</radio-group>

					</view>


					<view class="characteristic">
						<view class="text">
							特色服务
						</view>
						<view class="visit">
							<text class="texts">送货入户</text>
						</view>
						<view class="visit">
							<text class="texts">
								上门安装
							</text>
						</view>
					</view>

					<view class="purchase">
						<view class="text">
							购买数量
						</view>

						<view class="buy-count-steps">
							<text class="step-reduce" @tap="btnReduce">-</text>
							<text class="step-text">{{buySku.count}}</text>
							<text class="step-add" @tap="btnAdd">+</text>
						</view>

					</view>

					<view class="determine" @click="handleOk">
						<text class="determines">确定</text>
					</view>
				</view>

			</view>
		</view>
	</view>
</template>

<script>
	// 弹出层

	export default {
		components: {

		},
		data() {
			return {
				sku: {},
				show: false,
				buySku: {
					count: 1
				}
			}
		},
		props: {
			skuList: {
				type: Array,
				default: []
			}
		},
		methods: {
			handleOk() {
				var rs = {
					...this.sku,
					count: this.buySku.count
				}
				this.$emit('select-sku', rs);
			},
			// 打开弹窗
			openCard(type) {

				this.show = true;
				this.sku = this.skuList.length > 0 ? this.skuList[0] : {};

			},
			// 去掉弹窗
			goDel() {
				this.show = false
				this.sku = {};
			},
			colorSel(e) {
				// console.log(e.detail.value)
				this.sku = this.skuList.filter(item => item.id == e.detail.value)[0];
			},

			btnReduce() {
				if (this.buySku.count > 1) {
					this.buySku.count--;
				}
			},
			btnAdd() {
				if (this.buySku.count < this.sku.count) {
					this.buySku.count++;
				} else {
					uni.showToast({
						title: '库存只有' + this.sku.count + '个了!',
						duration: 1000,
						icon: 'none'
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.uniPopup {
		position: fixed;
		width: 100%;
		height: 100%;
		left: 0;
		top: 0;
		background-color: rgba(0, 0, 0, .5);
		z-index: 888;

		.popup {
			justify-content: center;

			.imgs {
				position: absolute;
				top: 140rpx;
				left: 100rpx;
				background: #333;
				border-radius: 20rpx;

				.imgss {
					border-radius: 20rpx;
					width: 192rpx;
					height: 192rpx;
				}
			}

			// 弹出层
			.background {

				width: 628rpx;
				height: 924rpx;
				background: #FFFFFF;
				border-radius: 40rpx;
				border-radius: 40rpx;
				margin: 180rpx auto;

				.name {
					position: absolute;
					top: 222rpx;
					left: 324rpx;

					.cname {
						font-family: PingFangSC-Semibold;
						font-size: 28rpx;
						color: #3E3E3E;
						letter-spacing: 2rpx;
					}

					.repertory {
						font-family: PingFangSC-Regular;
						font-size: 24rpx;
						color: #B0B0B0;
						letter-spacing: 1.71rpx;
					}
				}

				.icon {
					width: 41rpx;
					height: 41rpx;
					padding-top: 28rpx;
					float: right;
					padding-right: 50rpx;

					.icons {
						width: 41rpx;
						height: 41rpx;
					}
				}

				.classify {
					padding-top: 190rpx;
					padding-left: 68rpx;

					.text {
						font-family: PingFangSC-Semibold;
						font-size: 28rpx;
						color: #3E3E3E;
						letter-spacing: 2rpx;
					}

					.colors {
						display: flex;

						radio {
							display: none;
						}

						.color-item {
							box-sizing: border-box;
							float: left;
							width: 242rpx;
							height: 60rpx;
							color: #3E3E3E;
							font-size: 26rpx;
							text-align: center;
							line-height: 60rpx;
							background: #F2F4F3;
							border-radius: 10px;
							border-radius: 10px;
							margin: 10rpx;

							&:nth-child(2n-1) {
								margin-left: 0;
							}

							&.active {
								border: 2px #354E44 solid;
							}
						}
					}
				}

				.characteristic {
					.text {
						font-family: PingFangSC-Semibold;
						font-size: 28rpx;
						color: #3E3E3E;
						letter-spacing: 2rpx;
						margin-top: 31rpx;
						margin-left: 68rpx;
					}

					.visit {

						width: 380rpx;
						height: 60rpx;
						color: #3E3E3E;
						font-size: 26rpx;
						text-align: center;
						line-height: 60rpx;
						background: #F2F4F3;
						border-radius: 10px;
						border-radius: 10px;
						margin-left: 56rpx;

						margin-top: 10rpx;
						text-align: left;
						text-indent: 1em;

					}
				}

				.purchase {
					.text {
						font-family: PingFangSC-Semibold;
						font-size: 28rpx;
						color: #3E3E3E;
						letter-spacing: 2rpx;
						margin-top: 31rpx;
						margin-left: 68rpx;
					}

					.buy-count-steps {
						display: flex;
						margin-left: 352rpx;

						.step-reduce,
						.step-add,
						.step-text {
							width: 60rpx;
							height: 60rpx;
							background: #F1ECE7;
							border-radius: 50%;
							text-align: center;
							line-height: 60rpx;
							font-size: 30rpx;
							margin: 0 6rpx;
						}

						.step-text {
							width: 90rpx;
							border-radius: 30rpx;
						}
					}
				}

				.determine {
					width: 208rpx;
					height: 80rpx;
					background: #354E44;
					border-radius: 14rpx;
					border-radius: 14rpx;
					margin: 48rpx auto;
					text-align: center;

					.determines {
						line-height: 80rpx;


						font-family: PingFangSC-Semibold;
						font-size: 32rpx;
						color: #FFFFFF;
						letter-spacing: 2.29rpx;
					}
				}
			}
		}

	}
</style>
